// 主界面
;define(function(require, exports, module) {
    'use strict';
    var util = require("util");
    var base = require("base");
    var router = require("../hash/pageRouter");
    var dialog = require("dialog");
    var validate = require("validate");
    var databind = require("databind");
    var css_detail_info = require("./clientManage_financeEvidentiary.css");
//    var detail_info = require("./clientManage_details.js");
//    var css_detail_info = require("./clientManage_details.css");
     var html_auditState_Yes = require("../client/clientManage_auditStateYes.html");
    var html_auditState_No = require("../client/clientManage_auditStateNo.html");
    var pageIndex = 1,
        pageSize = 20,
        totalPageCount = 1,
        totalRecordCount = 0; //分页初始化
    var enterpriseId = "";
     var businessLicenceImage="";
    var certificateImage="";
    var legalPersonFrontImage= "";
    var legalPersonBackImage = "";
    var qualificationsImage = "";
    var creditReportImage = "";
    var str ="",
    	str1 = "",
    	str2 = "";
    var init = function(page){
    	$(".nav_active").removeClass("nav_active1");
		$("#financeEvidentiary").addClass("nav_active1");
    	enterpriseId = page.params.enterpriseId;
     	inquireEnterpriseDetail(enterpriseId);
		initEvent();
		
		router.init();
    };
    
    var initImage = function(){
    	str = "<a target='_blank' href='/finance/api/1.0/downloadFile.file?fileUuid="+businessLicenceImage+"'><img class=\"evidentiaryImg\" src=\"/finance/api/1.0/downloadFile.file?fileUuid="+businessLicenceImage+
     	"\">企业法人营业执照</a><a target='_blank' href='/finance/api/1.0/downloadFile.file?fileUuid="+certificateImage+"'><img class=\"evidentiaryImg\" src=\"/finance/api/1.0/downloadFile.file?fileUuid="+certificateImage+"\">组织机构代码证</a>";
		
		$("#businessLicence1").append(str);
		str1 = "<a target='_blank' href='/finance/api/1.0/downloadFile.file?fileUuid="+legalPersonFrontImage+"'><img class=\"evidentiaryImg\" src=\"/finance/api/1.0/downloadFile.file?fileUuid="+legalPersonFrontImage+
     	"\">法人证件照片正面</a><a target='_blank' href='/finance/api/1.0/downloadFile.file?fileUuid="+legalPersonBackImage+"'><img class=\"evidentiaryImg\" src=\"/finance/api/1.0/downloadFile.file?fileUuid="+legalPersonBackImage+"\">法人证件照片 反面</a>";
		$("#legalPerson1").append(str1);
		if(qualificationsImage.length>0 &&creditReportImage.length>0){
			str2 = "<a target='_blank' href='/finance/api/1.0/downloadFile.file?fileUuid="+qualificationsImage+"'><img class=\"evidentiaryImg\" src=\"/finance/api/1.0/downloadFile.file?fileUuid="+qualificationsImage+
     	"\">公司资质</a><a target='_blank' href='/finance/api/1.0/downloadFile.file?fileUuid="+creditReportImage+"'><img class=\"evidentiaryImg\" src=\"/finance/api/1.0/downloadFile.file?fileUuid="+creditReportImage+"\">信用报告</a>";

		}else if(qualificationsImage.length==0 &&creditReportImage.length>0){
			str2 +="<a target='_blank' href='/finance/api/1.0/downloadFile.file?fileUuid="+creditReportImage+"'><img class=\"evidentiaryImg\" src=\"/finance/api/1.0/downloadFile.file?fileUuid="+creditReportImage+"\">信用报告</a>";
		}else if(creditReportImage.length==0 && qualificationsImage.length>0){
			str2 +="<a target='_blank' href='/finance/api/1.0/downloadFile.file?fileUuid="+qualificationsImage+"'><img class=\"evidentiaryImg\" src=\"/finance/api/1.0/downloadFile.file?fileUuid="+qualificationsImage+
     	"\">公司资质</a>";
		}else{
			
		}
				$("#qualificationsImage1").html(str2);
				str2='';
    }
	var initEvent = function(){
		//若未登录，则返回登陆页面
		if(base.getData("sid")==null||base.getData("sid")==""||base.getData("sid")==undefined){
			top.location.href="../login/login.html";
		}
		
		//点击企业基本信息
		$(".enterpriseInfo").on("click", function() {
			router.route("client/clientManage_details.html?enterpriseId=" + enterpriseId, true);
		});

		$(".financeSituation").on("click", function() {
			router.route("client/clientManage_financeSituation.html?enterpriseId=" + enterpriseId);
		});
		
		//点击实名认证
		$(".authenticationState").on("click", function() {
			router.route("client/clientManage_authentication.html?enterpriseId=" + enterpriseId, true);
		});
		
		//所属客户
		$(".financeBelongs").on("click", function() {
			router.route("client/clientManage_belongs.html?enterpriseId=" + enterpriseId);
		});
    };
    
    //查询企业详细信息
	var inquireEnterpriseDetail = function(enterpriseId) {
		base.fnAjax({
			action: "inquireEnterpriseDetail.json",
			oData: {
				enterpriseId: enterpriseId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					businessLicenceImage = data.datas[0].businessLicenceImage;
					certificateImage = data.datas[0].certificateImage;
					legalPersonFrontImage = data.datas[0].legalPersonFrontImage;
					legalPersonBackImage = data.datas[0].legalPersonBackImage;
					qualificationsImage = data.datas[0].qualificationsImage;
					creditReportImage = data.datas[0].creditReportImage;
					initImage();
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
    
    return {
        init:init
    };
});